import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useTokenStore = defineStore('token', () => {
  //定义一个响应式状态
  const token = ref(null);
  //定义getter 方法
  const tokenStr = computed(() => {
    return token.value;
  })

  const updateToken = (tk) => {
    token.value = tk
  }

  const $reset = () =>{
    token.value = null
  };
  return { token, tokenStr, updateToken, $reset }
}, {
  persist: {
    key: 'token',
    storage: sessionStorage
  }
})
